.\"	$OpenBSD: ERR_put_error.3,v 1.9 2018/03/27 17:35:50 schwarze Exp $
.\"	OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
.\"
.\" This file was written by Ulf Moeller <ulf@openssl.org>.
.\" Copyright (c) 2000, 2016 The OpenSSL Project.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in
.\"    the documentation and/or other materials provided with the
.\"    distribution.
.\"
.\" 3. All advertising materials mentioning features or use of this
.\"    software must display the following acknowledgment:
.\"    "This product includes software developed by the OpenSSL Project
.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
.\"
.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
.\"    endorse or promote products derived from this software without
.\"    prior written permission. For written permission, please contact
.\"    openssl-core@openssl.org.
.\"
.\" 5. Products derived from this software may not be called "OpenSSL"
.\"    nor may "OpenSSL" appear in their names without prior written
.\"    permission of the OpenSSL Project.
.\"
.\" 6. Redistributions of any form whatsoever must retain the following
.\"    acknowledgment:
.\"    "This product includes software developed by the OpenSSL Project
.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: March 27 2018 $
.Dt ERR_PUT_ERROR 3
.Os
.Sh NAME
.Nm ERR_put_error ,
.Nm ERR_add_error_data ,
.Nm ERR_add_error_vdata
.Nd record an OpenSSL error
.Sh SYNOPSIS
.In openssl/err.h
.Ft void
.Fo ERR_put_error
.Fa "int lib"
.Fa "int func"
.Fa "int reason"
.Fa "const char *file"
.Fa "int line"
.Fc
.Ft void
.Fo ERR_add_error_data
.Fa "int num"
.Fa ...
.Fc
.Ft void
.Fo ERR_add_error_vdata
.Fa "int num"
.Fa "va_list arg"
.Fc
.Sh DESCRIPTION
.Fn ERR_put_error
adds an error code to the thread's error queue.
It signals that the error of reason code
.Fa reason
occurred in function
.Fa func
of library
.Fa lib ,
in line number
.Fa line
of
.Fa file .
This function is usually called by a macro.
.Pp
.Fn ERR_add_error_data
associates the concatenation of its
.Fa num
string arguments with the error code added last.
.Fn ERR_add_error_vdata
is similar except the argument is a
.Vt va_list .
Use of
.Fn ERR_add_error_data
and
.Fn ERR_add_error_vdata
is deprecated inside of LibreSSL in favour of
.Xr ERR_asprintf_error_data 3 .
.Pp
.Xr ERR_load_strings 3
can be used to register error strings so that the application can
generate human-readable error messages for the error code.
.Pp
Each sub-library has a specific macro
.Fn XXXerr f r
that is used to report errors.
Its first argument is a function code
.Dv XXX_F_* ;
the second argument is a reason code
.Dv XXX_R_* .
Function codes are derived from the function names
whereas reason codes consist of textual error descriptions.
For example, the function
.Fn ssl23_read
reports a "handshake failure" as follows:
.Pp
.Dl SSLerr(SSL_F_SSL23_READ, SSL_R_SSL_HANDSHAKE_FAILURE);
.Pp
Function and reason codes should consist of upper case characters,
numbers and underscores only.
The error file generation script translates function codes into function
names by looking in the header files for an appropriate function name.
If none is found it just uses the capitalized form such as "SSL23_READ"
in the above example.
.Pp
The trailing section of a reason code (after the "_R_") is translated
into lower case and underscores changed to spaces.
.Pp
Although a library will normally report errors using its own specific
.Fn XXXerr
macro, another library's macro can be used.
This is normally only done when a library wants to include ASN.1 code
which must use the
.Fn ASN1err
macro.
.Sh SEE ALSO
.Xr ERR 3 ,
.Xr ERR_asprintf_error_data 3 ,
.Xr ERR_load_strings 3
.Sh HISTORY
.Fn ERR_put_error
first appeared in SSLeay 0.4.4.
.Fn ERR_add_error_data
first appeared in SSLeay 0.9.0.
Both functions have been available since
.Ox 2.4 .
.Pp
.Fn ERR_add_error_vdata
first appeared in OpenSSL 1.0.1 and has been available since
.Ox 5.3 .
